<?php
namespace tp5_lib\common\controller;

use think\Controller;
use think\facade\Session;
use tp5_lib\access\logic\Access;

/**
 * 依赖用户模块的控制器的基类
 */
class BaseController extends Controller
{
    public function checkLogin()
    {
        if(!$user=Session::get("user")){
            $this->error("用户未登录",url("user/login/login"));
        }
        return $user;
    }
    public function checkRole($role)
    {
        $user=Session::get("user");
        if(!Access::checkRole($role)){
            if($user){
                $this->error("没有权限查看",url("user/index/index"));
            }
            else{
                $this->error("用户未登录",url("user/login/login"));
            }
        }
        return $user;
    }
    public function checkPrivilege($privilege)
    {
        $user=Session::get("user");
        if(!Access::checkPrivilege($privilege)){
            if($user){
                $this->error("没有权限查看",url("user/index/index"));
            }
            else{
                $this->error("用户未登录",url("user/login/login"));
            }
        }
        return $user;
    }
}
